VS Code 运行生成任务(Run Build Task):以g++编译一个C++程序为例

您所在的位置:网站首页 vs code 只编译不运行 VS Code 运行生成任务(Run Build Task):以g++编译一个C++程序为例

VS Code 运行生成任务(Run Build Task):以g++编译一个C++程序为例

2024-07-17 00:04| 来源: 网络整理| 查看: 265

添加一个任务步骤如下:

一、点击终端中运行生成任务

点击终端中运行生成任务

二、首次运行,需要配置生成任务首次运行,需要配置生成任务 三、选择用模板创建 tasks.json 文件

选择用模板创建 tasks.json 文件

四、选择 Others 运行任意外部命令的示例

选择 Others 运行任意外部命令的示例

五、创建 tasks.json 成功,编辑之

创建 tasks.json 成功,编辑之 本本以用 g++ 编译 hello.cpp 为例,将 tasks.json 配置如下:

{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", // 取个名字 "type": "shell", "command": "g++ -g hello.cpp -o hello", // 执行的命令 "group": { // 从这里 "kind": "build", "isDefault": true }, // 到这里,设置为默认构建任务,按Ctrl+Shift+B立即执行,不必选择 "problemMatcher": "$gcc"// 问题匹配程序 } ] }

编辑保存,按 Ctrl+Shift+B 执行结果如下图: 在终端查看编译器输出

软件版本:

Visual Studio Code 1.30.1GCC 8.2.0

参考资料:

C++Now 2018: Rong Lu “C++ Development with Visual Studio Code”define task as the default build task

源码下载(包含调试 launch.json)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3